package com.example.exampleretry.controller;

import com.example.exampleretry.dto.CreateCustomerDTO;
import com.example.exampleretry.entity.Customer;
import com.example.exampleretry.repository.CustomerRepository;
import com.example.exampleretry.service.CustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Tag(name = "用户信息")
@RequiredArgsConstructor
@RequestMapping("user")
@RestController
public class UserController {
    private final CustomerService customerService;

    @Operation(summary = "创建用户")
    @PostMapping("create")
    public Mono<Customer> create(@RequestBody CreateCustomerDTO dto) {
        Customer customer = Customer.builder().customerName(dto.getCustomerName()).build();
        return this.customerService.createCustomer(customer);
    }

    @Operation(summary = "查询所有")
    @PostMapping("all")
    public Flux<Customer> all() {
        return this.customerService.findAll();
    }
}
